package internalMail;

import java.awt.Color;
import java.sql.SQLException;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import basic.ClientConsole;
import com.sun.rowset.CachedRowSetImpl;

import flexibility.CachedRowSetTableModel;

public class showMailUpper {

	private CachedRowSetTableModel data;
	
	public void showMail(createMailBox cmb, ClientConsole myConnection, CachedRowSetImpl crs){
		//this will show the messages
	cmb.mailScreen.setVisible(true);
		try {
			// if(ssc.getSemesterForEdit()==1){
			cmb.table.setModel(data = new CachedRowSetTableModel(crs));
			DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
			centerRenderer.setHorizontalAlignment(JLabel.CENTER);
			for (int i = 0; i < cmb.table.getColumnCount(); i++)
				cmb.table.getColumnModel().getColumn(i)
						.setCellRenderer(centerRenderer);
			
			//csw.table.setEnabled(false);
			// }
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			int i = 0;//number of messages
			crs.beforeFirst();
			while(crs.next()){
				i++;
			}
			cmb.lblYouHave.setText("You have "+ i + " new messages");
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
}
